#include "VModuleSettingItemDlg.h"
#include "ui_VModuleSettingItemDlg.h"

#include <QLineEdit>
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QComboBox>
#include <QSizePolicy>
#include <QListView>

#include <QDebug>

VModuleSettingItemDlg::VModuleSettingItemDlg(QString title, QString comment, QString value, QWidget *parent):
    QWidget(parent),
    ui(new Ui::VModuleSettingItemDlg)
{
    ui->setupUi(this);

    ui->label_name->setText(title);
    ui->label_comment->setText(comment);
    if(comment.length() == 0)
    {
        this->layout()->removeWidget(ui->label_comment);
        _is_comment = false;
    }

    ui->lineEdit->setText(value);

    ui->comboBox->hide();
    type = "lineedit";

}

VModuleSettingItemDlg::VModuleSettingItemDlg(QString title, QString comment, QStringList selects, QString current_select, QWidget *parent):
    QWidget(parent),
    ui(new Ui::VModuleSettingItemDlg)
{
    ui->setupUi(this);
    ui->label_name->setText(title);
    ui->label_comment->setText(comment);
    if(comment.length() == 0)
    {
        this->layout()->removeWidget(ui->label_comment);
        _is_comment = false;
    }


    ui->comboBox->addItems(selects);
    ui->comboBox->setCurrentText(current_select);

    QSizePolicy policy = ui->comboBox->sizePolicy();
    policy.setHorizontalPolicy(QSizePolicy::Expanding);
    ui->comboBox->setSizePolicy(policy);

    // 设置combobox 为了使得item高度可以改变
    ui->comboBox->setView(new QListView());

    ui->lineEdit->hide();
    type = "combobox";
}

VModuleSettingItemDlg::~VModuleSettingItemDlg()
{
    delete ui;
}

QString VModuleSettingItemDlg::get_value()
{
    if(type == "lineedit")
    {
        return ui->lineEdit->text();
    }
    if(type == "combobox")
    {
        return ui->comboBox->currentText();
    }

    // 这里应该是出现了错误
    return "";
}
